//
//  ImagesController.swift
//  App
//
//  Created by melvyn on 2018/8/19.
//

import Foundation
import Vapor

class ImagesController: RouteCollection {
    
    func boot(router: Router) throws {
        let noAuth = router.grouped("images")
        noAuth.get(String.parameter, use: requestImage)
    }
    
    func requestImage(_ req: Request) throws -> Future<Response> {
        let asset = try req.parameters.next(String.self)
        let saveURL = URL.init(fileURLWithPath: imageURL).appendingPathComponent(asset)
        return try req.streamFile(at: saveURL.path)
    }
}
